export function createStore(reducer) {
    return {
        state: reducer(undefined, { type: '@@REDUX_INIT' }),

        getState() {
            return this.state
        },

        // 这样return对象，内部进行异步action处理，this可能获取不到哦
        dispatch(action) {
            this.state = reducer(this.state, action)
            this.onStateChange();
        },

        subscribe(listener) {
            this.onStateChange = listener
            return () => {
                this.onStateChange = null
            }
        },

        onStateChange() {
            console.log("state change")
        }
    }
}